; this short program for emu8086 shows how to keep constant temperature
; using heater and thermometer (between 60?to 80?,
; it is assumed that air temperature is lower 60?

; thermometer.exe is started automatically from c:\emu8086\devices.
; it is also accessible from the "virtual devices" menu of the emulator.

#start=thermometer.exe#

; temperature rises fast, thus emulator should be set to run at the maximum speed.

; if closed, the thermometer window can be re-opened from emulator's "virtual devices" menu.



#make_bin#

name "thermo"

; set data segment to code segment:
mov ax, cs
mov ds, ax
mov  bl,0Ah
mov  bh,0Ah
start:

in al, 125

cmp al, 50
jl  low  
jz  delay
cmp al, 80
;jle  ok
jg   high
jz  delay1

low:
mov al, 1
out 127, al   ; turn heater "on".
jmp ok

high:
mov al, 0
out 127, al   ; turn heater "off". 

ok:
jmp start   ; endless loop.
delay:
mov     cx, 00h    ;    004C4B40h = 5,000,000
mov     dx, 4B40h
mov     ah, 86h
int     15h

cmp bl,00H
jz low
dec bl
jz low
mov al,0
out 127,al
in al,125
cmp al,50
jl continue
jmp ok
continue:mov al,1
out 127,al
jmp ok
delay1:
mov     cx, 00h    ;    004C4B40h = 5,000,000
mov     dx, 4B40h
mov     ah, 86h
int     15h
cmp bh,00H
jz off
dec bh
jz off
mov al,0
out 127,al
in al,125
cmp al,80
jl continue
jmp ok
off:
mov al,0
out 127,al
in al,125
cmp al,0
jz ok